package com.example.controller;

import com.example.dao.ComputerMapper;
import com.example.domain.Computer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/2/11.
 */
@RestController
@CrossOrigin
public class TestController {
    @Autowired
    private ComputerMapper computerMapper;

    @RequestMapping("/test")
    public String test(){
        return "test";
    }
    @RequestMapping("/getAll")
    public Map<String,Object> getAll(String ip,int current,int size){
        int start = (current-1>=0?(current-1):0)* size;
        List<Computer> computers = computerMapper.getList(ip, start, size);
        int total = computerMapper.total(ip);
        Map<String,Object> result = new HashMap<String,Object>();
        Map<String,Object> page = new HashMap<String,Object>();
        result.put("list",computers);
        page.put("current",current);
        page.put("size",size);
        page.put("total",total);
        result.put("page",page);
        return result;
    }
}
